<template>
	<view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:up="upOption">
			<view class="p-l-20 p-r-20 m-t-20">
				<com-item :list="list" @rateClick="rateClick"></com-item>
			</view>
			
		</mescroll-body>
	</view>
</template>

<script>
	import {appraiseList,appraiseDel} from '@/api/car';
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list:[],
				driver_id:null,
				upOption: {
					empty: {
						icon: '/static/images/news_null.png',
						tip: "暂无数据",
					}
				},
			}
		},
		onLoad(option) {
			this.driver_id = option.id
			// this.getAppraiseList()
		},
		methods: {
			rateClick(id){
				var _this = this;
				uni.showModal({
					title:'提示',
					content:'是否删除该评论',
					success:res=>{
						if(res.confirm){
							_this.appraiseDelFun(id)
						}
					}
				})
				
			},
			appraiseDelFun(id){
				appraiseDel({id}).then(res=>{
					if(res.code==1){
						this.$toast({
							title:'删除成功'
						})
						this.downCallback();
					}
				})
			},
			upCallback(page) {
				let {driver_id} = this;
				appraiseList({
					driver_id,
					limit:page.size,
					page:page.num
				}).then(({
					data
				}) => {
					if (page.num == 1) this.list = [];
					let curPageData = data.lists;
					let curPageLen = curPageData.length;
					let hasNext = !!data.more;
					this.list = this.list.concat(curPageData);
					this.mescroll.endSuccess(curPageLen, hasNext);
				}).catch(() => {
					this.mescroll.endErr()
				})
			},
			getAppraiseList(){
				let {driver_id} = this;
				appraiseList({driver_id}).then(res=>{
					this.list = res.data.list
				})
			}
		}
	}
</script>

<style>

</style>
